from typing import List


class Solution:
    def checkSubarraySum(self, nums: List[int], k: int) -> bool:
        d = {0: -1}
        pre = 0
        for index, num in enumerate(nums):
            pre += num
            rem = pre % k
            i = d.get(rem, index)
            if i == index:
                d[rem] = index
            elif i <= index - 2:
                return True
        return False


# 返回是否存在
def func(nums: List[int], k: int) -> bool:
    if len(nums) < 2:
        return False
    for i in range(len(nums) - 2):
        for j in range(2, len(nums) - i):
            temp = sum(nums[i:i+j])
            if temp > 0 and temp % k == 0:
                return True
    return False


# 若有，返回该子数组
def func1(nums: List[int], k: int):
    if len(nums) < 2:
        return False
    for i in range(len(nums) - 2):
        for j in range(2, len(nums) - i):
            temp = sum(nums[i:i+j])
            if temp > 0 and temp % k == 0:
                return nums[i:i+j]
    return False


if __name__ == '__main__':
    t = [23, 2, 4, 6, 7]
    s = Solution()
    # print(s.checkSubarraySum(t, 6))
    print(func1(t, 13))
